import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { APIBase, ListOption } from 'app/modules/base/api-base';

@Injectable({
  providedIn: 'root',
})
export class TaskService extends APIBase<any, Task> {
  constructor(protected http: HttpClient) {
    super(http, '/api/admin/task');
  }
  //添加任务 step3 获取架构
  getAddOptions(acch?){
    let url =  acch?`/api/admin/platform?architecture=${acch}`:'/api/admin/platform'
    return this.http.get(url).toPromise();
  }
  checkParmas(t){
    let url =  '/api/admin/client_task';
    return this.http.post(url, t).toPromise();
  }
}

export interface Job {
  id: number;
}

export interface Task {
  id: string;
  sort_id: number;
  type: number;
  operator: string;
  created_at: string;
  start_at: string;
  status: number;
  jobs: Job[];
}

export enum TaskType {
  All = 1001 - 10,
  SystemUpgrade = 1001,
  SoftwareUpgrade,
  Script,
  Message,
  Policy,
  UsbAuth = 1008,
  DetelePc = 1009,
  Client = 1010,
}

export enum TaskPeriod {
  All = 0x8200 - 1,
  Now = 0x8200,
  Timing,
  Schedule,
}

export enum TaskStatus {
  All = 0x8300 - 1,
  Waiting = 0x8300,
  Running,
  Failed,
  Finish,
  Cancel,
  Pause,
}

export enum TaskTarget {
  All = 0x8400 - 1,
  Zone = 0x8400,
  Computer,
  Personnel,
  Software,
  ComputerSoftware,
  ZoneSoftware,
  ZoneAndUser,
  AreaComputer,
  DetelePc = 1009 ,
  Client = 1010,

}

export interface TaskListOption extends ListOption {
  category: TaskCategory;
  period_type?: TaskPeriod;
  status?: TaskStatus[];
  type?: TaskType;
  since?: TaskSince;
  area_id?: number;
}

export type TaskSince = 'today' | 'month' | 'year';
export type TaskCategory = 'all' | 'running' | 'history' | 'schedule';
